<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <title>特殊运价发布</title>
    </head>
    <body>
        <table width="100%" border="0" class="admin">
            <tr>
                <td width=100>
                    <span class="red">*</span>航空公司:
                </td>
                <td>
                    <input type="text" size="50" name="form_airwaysname" id="form_airwaysname" />
                </td>
                <td>
                    选择待发布销售政策的航空公司名称
                </td>
            </tr>
            <tr>
                <td colspan=2 id="form-ct-itemselector">
                    &nbsp;
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td>
                    适用航班：
                </td>
                <td>
                    <input type="text" size="30" name="form_flights" id="form_flights" />
                </td>
                <td>
                    输入该政策所适用的航班（如为所有则不填，如有多个特殊航班请用'/'隔开，如CA1522/CA1856）
                </td>
            </tr>
            <tr>
                <td>
                    <span class="red">*</span>折扣范围：
                </td>
                <td>
                    <table>
                        <tr>
                            <td>
                                <input type="text" size="10" name="form_discountfrom" id="form_discountfrom" />
                            </td>
                            <td>
                                &nbsp;到&nbsp;
                            </td>
                            <td>
                                <input type="text" size="10" name="form_discountto" id="form_discountto" />
                            </td>
                        </tr>
                    </table>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td>
                    <span class="red">*</span>B客户折扣率：
                </td>
                <td>
                    <input type="text" size="10" name="rake_off" id="rake_off" />
                </td>
                <td>
                    请输入异地同行客户折扣率（如7扣，输入7） 
                </td>
            </tr>
            <tr>
                <td>
                    <span class="red">*</span>优惠日期:
                </td>
                <td>
                    <table>
                        <tr>
                            <td>
                                <input type="text" size="10" name="form_datebegin" id="form_datebegin" />
                            </td>
                            <td>
                                &nbsp;到&nbsp;
                            </td>
                            <td>
                                <input type="text" size="10" name="form_dateend" id="form_dateend" />
                            </td>
                        </tr>
                    </table>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td>
                    是否启用运价:
                </td>
                <td>
                    <table border=0>
                        <tr>
                            <td>
                                启用
                            </td>
                            <td>
                                <input type="radio" name="is_released" value="启用" id="is_released" />
                            </td>
                            <td>
                                关闭
                            </td>
                            <td>
                                <input type="radio" name="is_released" value="关闭" id="is_released" />
                            </td>
                        </tr>
                    </table>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td>
                    客票类型:
                </td>
                <td>
                    <table border=0>
                        <tr>
                            <td>
                                B2B
                            </td>
                            <td>
                                <input type="radio" name="ticket_payment_type" value="启用" id="ticket_payment_type" />
                            </td>
                            <td>
                                BSP
                            </td>
                            <td>
                                <input type="radio" name="ticket_payment_type" value="关闭" id="ticket_payment_type" />
                            </td>
                        </tr>
                    </table>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td>
                    是否换PNR:
                </td>
                <td>
                    <table border=0>
                        <tr>
                            <td>
                                是
                            </td>
                            <td>
                                <input type="radio" name="conversion_pnr" value="启用" id="conversion_pnr" />
                            </td>
                            <td>
                                否
                            </td>
                            <td>
                                <input type="radio" name="conversion_pnr" value="关闭" id="conversion_pnr" />
                            </td>
                        </tr>
                    </table>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td align="center" border="0" colspan=2>
                    <table>
                        <tr>
                            <td>
                                <div id="btn_submit">
                                </div>
                            </td>
                            <td>
                                <div id="btn_cancel">
                                </div>
                            </td>
                        </tr>
                    </table>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;
                </td>
                <td>
                    &nbsp;
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;
                </td>
                <td>
                    &nbsp;
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
        </table>
        <script>
            Ext.onReady(function(){
                /*
                 * Ext.ux.ItemSelector Example Code
                 */
                Ext.form.Field.prototype.msgTarget = 'side';
                var airwaysname = new Ext.form.ComboBox({
                    store: new Ext.data.Store({
                        proxy: new Ext.data.HttpProxy({
                            url: '/admin/getInternalAirways'
                        }),
                        reader: new Ext.data.JsonReader({
                            root: 'root',
                            id: 'id'
                        }, ['id', 'airways_name'])
                    }),
                    applyTo: 'form_airwaysname',
                    name: 'airways_name',
                    loadingText: '正在加载...',
                    displayField: 'airways_name',
                    valueField: 'id',
                    mode: 'remote',
                    triggerAction: 'all',
                    hiddenName: 'airways_name_id',
                    fieldLabel: '航空公司',
                    emptyText: '请选择...',
                    editable: false,
                    allowBlank: false,
                    width: 80,
                    maxHeight: 150,
                    tabIndex: 4
                });
                var flights = new Ext.form.TextField({
                    fieldLabel: '适用航班',
                    //allowBlank: false,
                    name: 'airport_name',
                    anchor: '90%',
                    applyTo: 'form_flights'
                });
                
                var discountFrom = new Ext.form.ComboBox({ //combobox   
                    name: 'discountfrom',
                    fieldLabel: '性别',
                    width: '80',
                    resiable: true,
                    typeAhead: true,
                    allowBlank: false,
                    handleHeight: 100, //   
                    displayField: 'key',
                    valueField: 'value',
                    selectOnFocus: true,
                    mode: 'local',
                    selectOnFocus: true,
                    triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
                    readOnly: true,
                    emptyText: '选择类型...',
                    store: new Ext.data.Store({
                        data: [['45', '45折'], ['50', '50折'], ['55', '55折'], ['60', '60折'], ['65', '65折'], ['70', '70折'], ['75', '75折'], ['80', '80折']],
                        reader: new Ext.data.ArrayReader({
                            id: 0
                        }, [{
                            name: 'value'
                        }, {
                            name: 'key'
                        }])
                    }), //数据储存到这个comboBox   
                    anchor: '90%',
                    applyTo: 'form_discountfrom'
                });
                var discountTo = new Ext.form.ComboBox({ //combobox   
                    name: 'discountto',
                    fieldLabel: '性别',
                    width: '80',
                    resiable: true,
                    typeAhead: true,
                    allowBlank: false,
                    handleHeight: 100, //   
                    displayField: 'key',
                    valueField: 'value',
                    selectOnFocus: true,
                    mode: 'local',
                    selectOnFocus: true,
                    triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
                    readOnly: true,
                    emptyText: '选择类型...',
                    store: new Ext.data.Store({
                        data: [['45', '45折'], ['50', '50折'], ['55', '55折'], ['60', '60折'], ['65', '65折'], ['70', '70折'], ['75', '75折'], ['80', '80折']],
                        reader: new Ext.data.ArrayReader({
                            id: 0
                        }, [{
                            name: 'value'
                        }, {
                            name: 'key'
                        }])
                    }), //数据储存到这个comboBox   
                    anchor: '90%',
                    applyTo: 'form_discountto'
                });
                
                var rakeOff = new Ext.form.NumberField({
                    fieldLabel: '适用航班',
                    allowBlank: false,
                    name: 'rake_off',
                    anchor: '90%',
                    applyTo: 'rake_off'
                });
                
                var isReleased = new Ext.form.Radio({
                    fieldLabel: '启用',
                    name: 'is_released',
                    checked: true,
                    value: '1',
                    applyTo: 'is_released'
                });
                var ticketPaymentType = new Ext.form.Radio({
                    fieldLabel: '关闭',
                    name: 'ticket_payment_type',
                    checked: true,
                    value: '1',
                    applyTo: 'ticket_payment_type'
                });
                var conversionPNR = new Ext.form.Radio({
                    fieldLabel: '关闭',
                    name: 'conversion_pnr',
                    checked: true,
                    value: '1',
                    applyTo: 'conversion_pnr'
                });
                
                var dateBegin = new Ext.form.DateField({
                    fieldLabel: '日期从',
                    applyTo: 'form_datebegin',
                    name: 'airports_datebegin',
                    id: 'airports_datebegin',
                    format: 'Y-m-d', //格式化日期   
                    width: '80',
                    //disabledDays: [0,6],	//不让选择周六，周日   
                    //disabledDaysText: "周末要休息",   
                    invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
                    allowBlank: false,
                    inputType: '2008-01-01',
                    anchor: '90%',
                    vtype: 'daterange',
                    endDateField: 'airports_dateend',
                    listeners: {
                        select: function(field, e){
                            Ext.MessageBox.alert('提示', '提交成功');
                        }
                    }//,
                    //onTriggerClick:function(){Ext.MessageBox.alert('提示', '提交成功');}
                    //value:'1975-01-01'
                    //maxValue:'1925-01-01'
                });
                var dateEnd = new Ext.form.DateField({
                    fieldLabel: '到',
                    applyTo: 'form_dateend',
                    name: 'airports_dateend',
                    id: 'airports_dateend',
                    format: 'Y-m-d', //格式化日期   
                    width: '80',
                    //disabledDays: [0,6],	//不让选择周六，周日   
                    //disabledDaysText: "周末要休息",   
                    invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
                    allowBlank: false,
                    inputType: '2008-01-01',
                    anchor: '90%',
                    vtype: 'daterange',
                    startDateField: 'airports_datebegin',
                    listeners: {
                        select: function(field, e){
                            Ext.MessageBox.alert('提示', '提交成功');
                        }
                    }//,
                    //onTriggerClick:function(){Ext.MessageBox.alert('提示', '提交成功');}
                    //value:'1975-01-01'
                    //maxValue:'1925-01-01'
                });
                
                var formSpecialOffer = new Ext.form.FormPanel({
                    labelWidth: 75,
                    width: 450,
                    url: '/ticket/save_special_offer_release',
                    defaultType: 'textfield',
                    items: [{
                        xtype: "itemselector",
                        name: "airports",
                        imagePath: "/images/multi_select",
                        drawUpIcon: false,
                        drawDownIcon: false,
                        drawLeftIcon: true,
                        drawRightIcon: true,
                        drawTopIcon: false,
                        drawBotIcon: false,
                        fieldLabel: "<span class='red'>*</span>目的地选择",
                        dataFields: ["code", "desc"],
                        //fromData: [[123, "One Hundred Twenty Three"], ["1", "One"], ["2", "Two"], ["3", "Three"], ["4", "Four"], ["5", "Five"], ["6", "Six"], ["7", "Seven"], ["8", "Eight"], ["9", "Nine"]],
                        fromData: <%=@airports_arraystr%>,
                        toData: [],
                        msWidth: 160,
                        msHeight: 200,
                        valueField: "code",
                        displayField: "desc",
                        //imagePath:"ext-ux/multiselect",
                        //switchToFrom:true,
                        toLegend: "已经选择的城市",
                        fromLegend: "可选城市",
                        toTBar: [{
                            text: "清除",
                            handler: function(){
                                var i = formItemSelector.getForm().findField("itemselector");
                                i.reset.call(i);
                            }
                        }]
                    }]
                });
                //, flights, airwaysname, discountFrom, discountTo, dateBegin, dateEnd,isReleased,rakeOff,ticketPaymentType
                formSpecialOffer.render("form-ct-itemselector");
                var submitButton = new Ext.Button({
                    text: '提交',
                    applyTo: 'btn_submit',
                    handler: onItemClick
                });
                var cancelButton = new Ext.Button({
                    text: '取消',
                    applyTo: 'btn_cancel',
                    handler: onItemClick
                });
                function onItemClick(item){
                    if (airwaysname.validate() && discountFrom.validate() && discountTo.validate() && dateBegin.validate() && dateEnd.validate()) {
                        if (discountFrom.getValue() > discountTo.getValue()) {
                            Ext.MessageBox.alert("提示", "折扣范围不正确！");
                        }
                        else if (formSpecialOffer.getForm().getValues(true).length == 9) {
                            Ext.MessageBox.alert("提示", "请按要求选择目的地城市！");
                        }
                        else {
                            var submitStr = "airwaysname=" + airwaysname.getValue() + "&";
                            submitStr += "flights=" + flights.getValue() + "&";
                            submitStr += "discountFrom=" + discountFrom.getValue() + "&";
                            submitStr += "discountTo=" + discountTo.getValue() + "&";
                            submitStr += "rakeOff=" + rakeOff.getValue() + "&";
                            submitStr += "isReleased=" + isReleased.getValue() + "&";
                            submitStr += "ticketPaymentType=" + ticketPaymentType.getValue() + "&";
                            submitStr += "conversionPNR=" + conversionPNR.getValue() + "&";
                            submitStr += "dateBegin=" + dateBegin.getValue() + "&";
                            submitStr += "dateEnd=" + dateEnd.getValue() + "&";
                            submitStr += formSpecialOffer.getForm().getValues(true);
                            Ext.Ajax.request({
                                url: '/ticket/add_special_offer_release/?' + submitStr,
                                method: 'GET',
                                success: function(result, request){
                                    Ext.MessageBox.alert('提示', '普通价格添加成功！');
                                },
                                failure: function(result, request){
                                    Ext.MessageBox.alert('提示', '普通价格添加失败!');
                                }
                            });
                            //formSpecialOffer.form.url="";
                            //alert(formSpecialOffer.form.url);
                            //alert(airwaysname.validate());
                            //alert(formSpecialOffer.getForm().getValues(true));
                            //formSpecialOffer.form.submit();
                        }
                    }
                    else {
                        Ext.MessageBox.alert("提示", "请按要求填写带<span class='red'>*</span>的必输值！");
                    }
                }
            });
        </script>
    </body>
</html>
